package com.kpmg.datalake.web.config;

import com.kpmg.datalake.common.enums.CacheTypeEnum;
import java.util.ArrayList;
import java.util.List;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 缓存服务配置
 *
 * @author Alex.zhao [alex.zhao@kpmg.com]
 * @since Created on azhao6 on 2018-08-22 11:00:12
 */
@Configuration
@EnableCaching
public class CacheConfiguration {

  @Bean
  public CacheManager cacheManager() {
    SimpleCacheManager cacheManager = new SimpleCacheManager();
    List<Cache> cacheList = new ArrayList<>();
    //数据字典缓存
    cacheList.add(new ConcurrentMapCache(CacheTypeEnum.DICT.getValue()));
    //多语言缓存
    cacheList.add(new ConcurrentMapCache(CacheTypeEnum.MULTILINGUAL.getValue()));
    //系统参数
    cacheList.add(new ConcurrentMapCache(CacheTypeEnum.SYSTEM_PARAM.getValue()));
    //用户登录
    cacheList.add(new ConcurrentMapCache(CacheTypeEnum.USER_LOGIN.getValue()));

    cacheManager.setCaches(cacheList);
    return cacheManager;
  }
}
